<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1"><title id="am137232">ALTER VIEW</title><body><p id="sql_command_desc">Changes properties of a view.</p><section id="section2"><title>Synopsis</title><codeblock id="sql_command_synopsis">ALTER VIEW [ IF EXISTS ] <varname>name</varname> ALTER [ COLUMN ] <varname>column_name</varname> SET DEFAULT <varname>expression</varname>

ALTER VIEW [ IF EXISTS ] <varname>name</varname> ALTER [ COLUMN ] <varname>column_name</varname> DROP DEFAULT

ALTER VIEW [ IF EXISTS ] <varname>name</varname> OWNER TO <varname>new_owner</varname>

ALTER VIEW [ IF EXISTS ] <varname>name</varname> RENAME TO <varname>new_name</varname>

ALTER VIEW [ IF EXISTS ] <varname>name</varname> SET SCHEMA <varname>new_schema</varname>

ALTER VIEW [ IF EXISTS ] <varname>name</varname> SET ( <varname>view_option_name</varname> [= <varname>view_option_value</varname>] [, ... ] )

ALTER VIEW [ IF EXISTS ] <varname>name</varname> RESET ( <varname>view_option_name</varname> [, ... ] )</codeblock></section><section id="section3">
      <title>Description</title>
      <p><codeph>ALTER VIEW</codeph> changes various auxiliary properties of a view. (If you want to
        modify the view's defining query, use <codeph>CREATE OR REPLACE VIEW</codeph>. </p>
      <p>To run this command you must be the owner of the view. To change a view's schema you
        must also have <codeph>CREATE</codeph> privilege on the new schema. To alter the owner, you
        must also be a direct or indirect member of the new owning role, and that role must have
          <codeph>CREATE</codeph> privilege on the view's schema. These restrictions enforce that
        altering the owner does not do anything you could not do by dropping and recreating the
        view. However, a superuser can alter ownership of any view.</p>
    </section><section id="section4"><title>Parameters</title><parml>
        <plentry>
          <pt><varname>name</varname></pt>
          <pd>The name (optionally schema-qualified) of an existing view.</pd>
        </plentry>
        <plentry>
          <pt><codeph>IF EXISTS</codeph></pt>
          <pd>Do not throw an error if the view does not exist. A notice is issued in this
            case.</pd>
        </plentry><plentry><pt><codeph>SET</codeph>/<codeph>DROP DEFAULT</codeph></pt>
          <pd>These forms set or remove the default value for a column. A view column's default
            value is substituted into any <codeph>INSERT</codeph> or <codeph>UPDATE</codeph> command
            whose target is the view, before applying any rules or triggers for the view. The view's
            default will therefore take precedence over any default values from underlying
            relations.</pd></plentry>
        <plentry>
          <pt><varname>new_owner</varname></pt>
          <pd>The new owner for the view. </pd>
        </plentry>
        <plentry>
          <pt><varname>new_name</varname></pt>
          <pd>The new name of the view.</pd>
        </plentry>
        <plentry>
          <pt><varname>new_schema</varname></pt>
          <pd>The new schema for the view.</pd>
        </plentry>
        <plentry>
          <pt><codeph>SET ( <varname>view_option_name</varname> [=
                <varname>view_option_value</varname>] [, ... ] )</codeph></pt>
          <pt><codeph>RESET ( <varname>view_option_name</varname> [, ... ] )</codeph></pt>
          <pd>Sets or resets a view option. Currently supported options are:<parml>
              <plentry>
                <pt><codeph>check_option</codeph> (string)</pt>
                <pd>Changes the check option of the view. The value must be <codeph>local</codeph>
                  or <codeph>cascaded</codeph>.</pd>
              </plentry>
            </parml><parml>
              <plentry>
                <pt><codeph>security_barrier</codeph> (boolean)</pt>
                <pd>Changes the security-barrier property of the view. The value must be a Boolean
                  value, such as <codeph>true</codeph> or <codeph>false</codeph>.</pd>
              </plentry>
            </parml></pd>
        </plentry></parml></section>
    <section>
      <title>Notes</title>
      <p>For historical reasons, <codeph>ALTER TABLE</codeph> can be used with views, too; however,
        the only variants of <codeph>ALTER TABLE</codeph> that are allowed with views are equivalent
        to the statements shown above.</p>
      <p>Rename the view <codeph>myview</codeph> to <codeph>newview</codeph>:</p>
      <codeblock>ALTER VIEW myview RENAME TO newview;</codeblock>
    </section>
    <section id="examples"><title>Examples</title>
      <p>To rename the view <codeph>foo</codeph> to <codeph>bar</codeph>:</p>
      <codeblock>ALTER VIEW foo RENAME TO bar;</codeblock>
      <p>To attach a default column value to an updatable view:</p>
      <codeblock>CREATE TABLE base_table (id int, ts timestamptz);
CREATE VIEW a_view AS SELECT * FROM base_table;
ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
INSERT INTO base_table(id) VALUES(1);  -- ts will receive a NULL
INSERT INTO a_view(id) VALUES(2);  -- ts will receive the current time</codeblock>
    </section>
  <section id="section6"><title>Compatibility</title><p><codeph>ALTER VIEW</codeph> is a Greenplum Database extension of the SQL standard.</p></section><section id="section7"><title>See Also</title><p><codeph><xref href="CREATE_VIEW.xml#topic1/cj20941">CREATE VIEW</xref></codeph>, <codeph><xref
            href="DROP_VIEW.xml#topic1/dn20941">DROP VIEW</xref></codeph> in the <i>Greenplum
          Database Utility Guide</i></p></section></body></topic>
